package com.psq.core.common.ui.dialog

import android.os.Bundle
import cn.wufuqi.recyclerviewbindingadapter.utils.viewBindingFragment
import com.psq.core.common.R
import com.psq.core.common.base.BaseDialogFragment
import com.psq.core.common.databinding.DialogLoadingBinding
import com.wukonganimation.tween.Tween
import com.wukonganimation.tween.TweenManager


/**
 * 加载对话框
 */
class LoadingDialog : BaseDialogFragment() {

    private val mBinding by viewBindingFragment(DialogLoadingBinding::bind)

    private var mTween: Tween? = null

    override fun getLayoutResId() = R.layout.dialog_loading


    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        mTween = TweenManager.builder(mBinding.ivLoading)
            .time(5000)
            .from(mutableMapOf("rotation" to 0))
            .to(mutableMapOf("rotation" to 360))
            .repeat(-1)
            .start()
    }

    override fun initWindow() {
        super.initWindow()
        //返回按钮不可取消
        isCancelable = false
        //点击透明不可取消
        setCanceledOnTouchOutside(false)
        //不显示对话框的半透明黑色背景
        isShowDialogTransparentBg = false
    }


    override fun onDestroy() {
        super.onDestroy()
        mTween?.remove()
        mTween = null
    }

}